import { createSlice } from "@reduxjs/toolkit";

const countStore = createSlice({
  name: "count",
  //初始化状态
  initialState: {
    count: 0,
  },
  //修改状态的方法，同步方法  支持直接修改
  reducers: {
    increment(state, payload) {
      console.log(payload, "payload");

      state.count++;
    },
    decrement(state) {
      state.count--;
    },
    randomNum(state, { payload }) {
      state.count += payload;
    },
  },
});
//结构出来actionCreater
const { increment, decrement, randomNum } = countStore.actions;
//获取reducer
const reducer = countStore.reducer;
//按需导出actionCreater
export { increment, decrement, randomNum };
//默认导出reducer
export default reducer;
